Skip to content

Fix eltype invalidation for SparsityPatternCSC#304

Merged
gdalle merged 2 commits intoJuliaDiff:mainfrom
ChrisRackauckas-Claude:fix-eltype-invalidation
Feb 27, 2026
Merged

Fix eltype invalidation for SparsityPatternCSC#304
gdalle merged 2 commits intoJuliaDiff:mainfrom
ChrisRackauckas-Claude:fix-eltype-invalidation

Conversation

@ChrisRackauckas-Claude
Copy link
Contributor

Summary

  • SparsityPatternCSC{Ti} <: AbstractMatrix{Bool} defines Base.eltype to return Ti (the index type) instead of Bool, causing 24,906 method invalidations when loading the package
  • Changed the custom method from Base.eltype to SparseArrays.indtype, since Ti is the index type, not the element type
  • The element type is now correctly inherited as Bool from AbstractMatrix{Bool}

Context

When profiling the TTFX (Time-To-First-Execution) of ModelingToolkit's DAE pipeline, SparseMatrixColorings was identified as the #1 source of method invalidations in the entire dependency tree. The eltype(::SparsityPatternCSC{T}) method invalidated Base.eltype(::AbstractArray), creating a cascade of 24,906 recompilations across all downstream packages.

Changes

  • src/graph.jl: Changed Base.eltype(::SparsityPatternCSC{T}) where {T} = T to SparseArrays.indtype(::SparsityPatternCSC{T}) where {T} = T
  • test/graph.jl: Updated test to check eltype returns Bool and added indtype test for Int

Test plan

  • Full test suite passes locally (50,486 pass, 7 broken (pre-existing), 0 fail)

🤖 Generated with Claude Code

SparsityPatternCSC{Ti} <: AbstractMatrix{Bool} but the custom
Base.eltype method was returning Ti (the index type) instead of Bool.
This caused 24,906 method invalidations when loading the package,
as it invalidated the backedge from Base.eltype(::AbstractArray).

Change the custom method to SparseArrays.indtype instead, since
that's what the type parameter Ti actually represents. The eltype
is now correctly inherited from AbstractMatrix{Bool}.

Co-Authored-By: Chris Rackauckas <[email protected]>
@oscardssmith
Copy link
Member

@ChrisRackauckas this is nonsense. eltype isn't supposed to return Bool

@gdalle
Copy link
Member

gdalle commented Feb 27, 2026

Actually this is a Boolean matrix so it seems to make sense. Test failures seem unrelated, I'll fix them on main and review properly tomorrow

@ChrisRackauckas
Copy link
Member

@oscardssmith struct SparsityPatternCSC{Ti<:Integer} <: AbstractMatrix{Bool}

@ChrisRackauckas
Copy link
Member

I'd argue you'd either need to do this or make it not an AbstractMatrix{Bool}. But the combination is 😅

@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.39%. Comparing base (1c3c9da) to head (20a2f01).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #304   +/-   ##
=======================================
  Coverage   99.39%   99.39%           
=======================================
  Files          20       20           
  Lines        2145     2145           
=======================================
  Hits         2132     2132           
  Misses         13       13           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@gdalle gdalle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, I'll merge and release if the tests pass

@gdalle gdalle merged commit 408d8f3 into JuliaDiff:main Feb 27, 2026
10 checks passed
@gdalle
Copy link
Member

gdalle commented Feb 27, 2026

Fix incoming in release 0.4.24, undergoing registration atm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants